package com.runda.partypolicy.app.page.adapter;


import android.text.Html;
import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.runda.partypolicy.R;
import com.runda.partypolicy.app.page.adapter.listener.OnItemClickListener;
import com.runda.partypolicy.app.repository.bean.ItemListData;
import com.runda.partypolicy.utils.CheckEmptyUtils;

import java.util.List;

import androidx.annotation.Nullable;

/**
 * author:  RD_YH
 * date:    2019/3/15
 * version: v1.0
 * description:
 */
public class Adapter_ListItem extends BaseQuickAdapter<ItemListData, BaseViewHolder> {
    OnItemClickListener itemOnClickListener;

    public void setItemOnClickListener(OnItemClickListener itemOnClickListener) {
        this.itemOnClickListener = itemOnClickListener;
    }

    public Adapter_ListItem(int layoutResId, @Nullable List<ItemListData> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, ItemListData item) {

        if (!CheckEmptyUtils.isEmpty(item.getTitle())) {
            helper.setText(R.id.tv_title, item.getTitle());
        }
        if (!CheckEmptyUtils.isEmpty(item.getStartTime())) {
            helper.setText(R.id.tv_start_time, item.getStartTime());
        }
        if (!CheckEmptyUtils.isEmpty(item.getEndTime())) {
            helper.setText(R.id.tv_end_time, item.getEndTime());
        }
        if (!CheckEmptyUtils.isEmpty(item.getDuration())) {
            helper.setText(R.id.tv_duration, item.getDuration());
        }
        if (!CheckEmptyUtils.isEmpty(item.getTitle())) {
            helper.setText(R.id.tv_title, item.getTitle());
        }
        if (!CheckEmptyUtils.isEmpty(item.getReason())) {
            helper.setText(R.id.tv_reason, item.getReason());
        }
        if (!CheckEmptyUtils.isEmpty(item.getProjectName())) {
            helper.setText(R.id.tv_project_name, item.getProjectName());
        }
        if (!CheckEmptyUtils.isEmpty(item.getStartUpTime())) {
            helper.setText(R.id.tv_startup_time, item.getStartUpTime());
        }
        if (!CheckEmptyUtils.isEmpty(item.getTime())) {
            helper.setText(R.id.tv_time, item.getTime());
        }
        if (!CheckEmptyUtils.isEmpty(item.getPrincipal())) {
            helper.setText(R.id.tv_principal, item.getPrincipal());
        }
        if (!CheckEmptyUtils.isEmpty(item.getFileName())) {
            helper.setText(R.id.tv_filename, item.getFileName());
        }
        if (!CheckEmptyUtils.isEmpty(item.getFileTime())) {
            helper.setText(R.id.tv_file_time, item.getFileTime());
        }
        if (!CheckEmptyUtils.isEmpty(item.getSubmitter())) {
            helper.setText(R.id.tv_submitter, item.getSubmitter());
        }

        if ("0".equals(item.getStatus())) {
            helper.setText(R.id.tv_status, Html.fromHtml("<font color='#FF9814'>未审批</font>"));


        } else if ("1".equals(item.getStatus())) {
            helper.setText(R.id.tv_status, "审批通过");
        } else if ("2".equals(item.getStatus())) {
            helper.setText(R.id.tv_status, Html.fromHtml("<font color='#FF9814'>未完成</font>"));
        } else if ("3".equals(item.getStatus())) {
            helper.setText(R.id.tv_status, Html.fromHtml("<font color='#999999'>已完成</font>"));
        }

        helper.setImageResource(R.id.item_image, item.getImage());
        String type = item.getType();

        if ("1".equals(type)) {


            helper.getView(R.id.ll_duration).setVisibility(View.VISIBLE);
            helper.getView(R.id.ll_reason).setVisibility(View.VISIBLE);

        } else if ("2".equals(type)) {
            helper.getView(R.id.ll_reason).setVisibility(View.VISIBLE);
            helper.getView(R.id.ll_duration).setVisibility(View.VISIBLE);

        } else if ("3".equals(type)) {

            //便捷请示
            helper.getView(R.id.ll_reason).setVisibility(View.GONE);

            helper.getView(R.id.ll_startup_time).setVisibility(View.GONE);
            helper.getView(R.id.ll_start_time).setVisibility(View.GONE);
            helper.getView(R.id.ll_project_name).setVisibility(View.GONE);
            helper.getView(R.id.tv_status).setVisibility(View.GONE);

        }


    }
}
